<?php
namespace Dry\Base;

class Base {

    private $container = NULL;

    private $file = '';

    private $data = array();

    public function __construct()
    {
        $this->container = $GLOBALS['container'];
    }

    public function get($name, $container=false)
    {
        return $this->container->get($name, $container);
    }

    public function invoke($name)
    {
        return $this->container->get($name, true)->get();
    }

    public function getInstance($name)
    {
        return $this->container->getInstance($name);
    }

    public function setFile($file)
    {
        $this->file = $file;
    }

    public function setData($data)
    {
        $this->data = $data;
    }

    public function render()
    {
        $twig = $this->getInstance('twig');
        return $twig->render($this->file, $this->data);
    }

    public function display()
    {
        echo $this->render();
    }

    public function go($url)
    {
        header("Location: {$url}");
        exit;
    }

}
?>
